package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 攻略目录实现类
 *
 * @author totoro93
 * @date 2019-01-11
 **/
@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService{
    @Autowired
    private StrategyCatalogMapper catalogMapper;

    @Override
    public PageInfo query(StrategyCatalogQueryObject queryObject) {
        PageHelper.startPage(queryObject.getCurrentPage(), queryObject.getPageSize());
        List<StrategyCatalog>list=catalogMapper.selectForList(queryObject);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        //判断有无指定序列，未指定序列默认给到最后
        if (strategyCatalog.getSequence()==null) {
            strategyCatalog.setSequence(catalogMapper.selectMaxSequence(strategyCatalog.getStrategy().getId())+1);
        }
        //判断状态



        if (strategyCatalog.getId() != null) {
            catalogMapper.updateByPrimaryKey(strategyCatalog);
        } else {
            catalogMapper.insert(strategyCatalog);
        }
    }

    @Override
    public List selectByStrategyId(Long strategyId) {
        return catalogMapper.selectByStrategyId(strategyId);
    }

}
